﻿
namespace Behemoth.SharePoint {

    using System;
    using System.Collections.Generic;
    using System.Text;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    using Behemoth.SharePoint;

    public enum FeatureCheckerScope {
        Site,
        Web
    }

    public static class FeatureChecker {
        // TODO re-implement static methods if needed

        public static bool IsFeatureActivated(FeatureCheckerScope scope, string featureName) {
            SPContext ctx = SPContext.Current;
            if (ctx == null)
                return false;
            Guid featureId;
            if (scope == FeatureCheckerScope.Web)
                featureId = ctx.WebFeatures.GetFeatureIdByName(featureName);
            else // Site
                featureId = ctx.SiteFeatures.GetFeatureIdByName(featureName);
            return (featureId != Guid.Empty);
        }

        public static bool IsFeatureActivated(FeatureCheckerScope scope, Guid featureId) {
            SPContext ctx = SPContext.Current;
            if (ctx == null)
                return false;
            if (scope == FeatureCheckerScope.Web)
                return ctx.WebFeatures.IsFeatureActivated(featureId);
            else // Site
                return ctx.SiteFeatures.IsFeatureActivated(featureId);
        }

    }

} // namespace
